const express = require("express");
const router = express.Router();
const {
  list,
  add,
  update,
  updatePassword,
  addRoleId,
  getRoleUserIds,
  del,
  details,
  uploadAvatar,
} = require("../../controllers/system/usersController");

const createUploadMiddleware = require("../../middlewares/createUploadMiddleware");

const { singleFileUpload } = createUploadMiddleware();

/**
 * 查询用户列表
 * GTE  /users/getUserList
 */
router.get("/getUserList", list);

/**
 * 新增用户
 * POST /users
 */
router.post("/add", add);

/**
 * 更新用户
 * PUT /users/update
 */
router.put("/update", update);

/**
 * 更新密码
 * PUT /users/updatePassword
 */
router.put("/updatePassword", updatePassword);

/**
 * 保存权限信息
 * PUT /users/addRoleId
 */
router.put("/addRoleId", addRoleId);

/**
 * 选中的角色列表
 * PUT /users/getRoleUserIds
 */
router.get("/getRoleUserIds", getRoleUserIds);

/**
 * 删除用户
 * DELETE /users/delete
 */
router.delete("/delete", del);

/**
 * 查询用户详情
 * GET /users/details
 */
router.get("/details", details);

/**
 * 上传头像
 *  POST /users/uploadAvatar
 */

router.post("/uploadAvatar", singleFileUpload("file"), uploadAvatar);

module.exports = router;
